﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.pager.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        //时间格式转换
        function date2str(date) {
            //null判断
            if (date == null) return "";
            //去掉左右的斜杠
            date = date.replace(/\//g, "");
            //将其转为一个日期对象
            eval("var d = new " + date + ";");
            //返回最终结果
            return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
        }
        var CLID=1;
        function Load() {
            $("#tb1 tr:gt(0)").live("click", function () {
                CLID = $(this).find("td :eq(0)").val();
                $("#dataLeft .dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "red");
                if ($(this).attr("id") == "3") {
                    $(".contentDiv div:first").hide();
                } else {
                    $(".contentDiv div:first").show();
                    $("#txtXj").val("");
                    MeaLoad();
                }

            });
        }
        //查询客户流失管理页面 
        function cha() {
            var cus = {
                action: "SelectCustomLosts",
                CusName: $("#txtCusName").val(),
                CusID: $("#txtCusID").val()
            };
            $("#pageDiv").empty().pager3("CustomerAll.ashx", cus, function (data) {
                //展示查询的结果
                $("#tb1 tr:gt(0)").remove();
                var tb1 = $("#tb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].CusID + '<input type="hidden" value="' + data[i].CLID + '" />';
                    tr.insertCell(-1).innerHTML = data[i].CusName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLOrderDate) || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLDate) || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLEnterDate) || "";

                    if (data[i].CLState == "1") {
                        tr.insertCell(-1).innerHTML = "流失报警" || "";
                        tr.insertCell(-1).innerHTML = '<img title="编辑" src="../images/33.gif" onclick="showEnter(' + data[i].CLID + ')" />' || "";
                        $(tr).attr("id", data[i].CLState);
                    }
                    else if (data[i].CLState == "2") {
                        tr.insertCell(-1).innerHTML = "暂缓流失" || "";
                        tr.insertCell(-1).innerHTML = '<img src="../images/bt_confirm.gif" title="暂缓流失" />' || ""
                        $(tr).attr("id", data[i].CLState);
                    }
                    else if (data[i].CLState == "3") {
                        tr.insertCell(-1).innerHTML = "确认流失" || "";
                        tr.insertCell(-1).innerHTML = '<img src="../images/bt_confirm.gif" title="确认流失" onclick="showEnter(' + data[i].CLID + ')" />' || ""
                        $(tr).attr("id", data[i].CLState);
                    }
                }
            });
        }
        function List() {
            $("#pageDiv").empty().pager2("QuanBuAll.asmx/SelectCustomLosts", {}, function (data) {
                //展示查询的结果
                $("#tb1 tr:gt(0)").remove();
                var tb1 = $("#tb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].CusID + '<input type="hidden" value="' + data[i].CLID + '" />';
                    tr.insertCell(-1).innerHTML = data[i].CusName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLOrderDate) || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLDate) || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CLEnterDate) || "";

                    if (data[i].CLState == "1") {
                        tr.insertCell(-1).innerHTML = "流失报警" || "";
                        tr.insertCell(-1).innerHTML = '<img title="编辑" src="../images/33.gif" onclick="showEnter(' + data[i].CLID + ')" />' || "";
                        $(tr).attr("id", data[i].CLState);
                    }
                    else if (data[i].CLState == "2") {
                        tr.insertCell(-1).innerHTML = "暂缓流失" || "";
                        tr.insertCell(-1).innerHTML = '<img src="../images/bt_confirm.gif" title="暂缓流失" />' || ""
                        $(tr).attr("id", data[i].CLState);
                    }
                    else if (data[i].CLState == "3") {
                        tr.insertCell(-1).innerHTML = "确认流失" || "";
                        tr.insertCell(-1).innerHTML = '<img src="../images/bt_confirm.gif" title="确认流失" onclick="showEnter(' + data[i].CLID + ')" />' || ""
                        $(tr).attr("id", data[i].CLState);
                    }
                }
            });

        }
        function AddLosts() {
            $.ajax({
                url: "QuanBuAll.asmx/AddLosts",
                type: "post",
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    if (obj.d > 0) {
                        alert("操作成功");
                    }
                },
                error: function (xmlhttp) {
                    alert("错误提示：" + xmlhttp.responseText);
                }
            }
               );
        }
        $(function () {
            AddLosts();//客户流失预警
            Load();//页面动态
            List();//加载
            MeaLoad();//暂缓流失
        });
        function MeaLoad() {
            $.get("LostsPage.ashx", { action: "find", CLID: parseInt(CLID) }, function (m) {
                //将服务器返回的结果，转为js的数组
                var arr = JSON.parse(m);
                //找到tb1这个表格，转为dom对象
                var tab = $("#tab").get(0);
                //删除原来的数据
                $(tab).find("tr").remove();
                //加载每一行
                for (var i = 0; i < arr.length; i++) {
                    //添加一行
                    var tr = tab.insertRow(-1);
                    tr.insertCell(-1).innerHTML = date2str(arr[i].MeDate)||"";
                    var tr = tab.insertRow(-1);
                    tr.insertCell(-1).innerHTML = arr[i].MeDesc || "";
                }
            });
        }
        function showEnter(id) {

            $.showModalDialog("LostEnter.htm?data=" + Math.random(), { id: id }, 500, 200, function (r) {
                List();
            });
        }
        function showEnter1(id) {

            $.showModalDialog("LostEnter1.htm?data=" + Math.random(), { id: id }, 500, 200, function (r) {
                List();
            });
        }
        function add() {
            var m = {
                action:"AddMeasures",
                CLID: parseInt(CLID),
                MeDesc: $("#txtXj").val()
            };
            //发起更新请求
            $.get("LostsPage.ashx", m, function (r) {
                if (r == "1") {
                    alert("添加成功");
                    MeaLoad();
                } else {
                    alert("添加失败");
                }
            });
        }

    </script>
</head>
<body>
    <div id="desDiv">
        <span>客户流失管理</span><br />
        显示即将流失的客户信息，并制定挽救措施
    </div>
    <table class="tableEdit">
        <tr>
            <th>
                客户名称：
            </th>
            <td>
                <input type="text" id="txtCusName" style="color:blue;width:140px" />
            </td>
            <th>
                客户编号：
            </th>
            <td>
                <input type="text" id="txtCusID" style="color:blue;width:140px" />
            </td>
        </tr>
        <tfoot>
            <tr>
                <td colspan="8">
                    <input type="button" value="查询" onclick="cha();" />
                </td>
            </tr>
        </tfoot>
    </table>
    <br />
    <div style="width: 1065px">
        <div id="dataLeft">
            <table class="dataTable" id="tb1">
                <tr>
                    <th align="center">
                        客户编号
                    </th>
                    <th align="center">
                        客户名称
                    </th>
                    <th align="center">
                        上次下单时间
                    </th>
                    <th align="center">
                        报警时间
                    </th>
                    <th align="center">
                        流失时间
                    </th>
                    <th align="center">
                        状态
                    </th>
                    <th align="center">
                        操作
                    </th>
                </tr>
            </table>
            <div id="pageDiv">
            </div>
        </div>
        <div id="dataRight">
            <div class="menuDiv">
                <div  style="background-image:url(../images/bg.gif)">暂缓流失措施
                </div>
            </div>
            <div class="contentDiv">
                <div>
                    <table class="tableEdit" id="tb2">
                        <thead>
                            <tr>
                                <td colspan="2">添加暂缓措施</td>
                            </tr>
                        </thead>
                        <tr>
                            <th>暂缓措施细节：</th>
                            <td>
                                <textarea id="txtXj" style="width:90%"></textarea>
                            </td>
                        </tr>
                        <tfoot>
                            <tr>
                                <td colspan="4">
                                    <input type="button" value="添加" onclick="add();" />&nbsp;&nbsp;
                                </td>
                            </tr>
                            <label id="1" style="txt-align:center"></label>
                        </tfoot>
                    </table>

                    <table class="dataTable" id="tab">
                        
                    </table>

                </div>
            </div>
        </div>
    </div>
</body>
</html>
